import os 
import numpy as np
import win32com.client as win32 
import sys

with open('input.txt', 'r') as F:
    l1=float(F.readline().strip())  #condenser T 25-35
    l2=float(F.readline().strip())  # reflux ratio 0.5-6
    l3=float(F.readline().strip())  #Heat duty 0.2-1 kw
    l4=float(F.readline().strip())  #time 5-24 hr
    l5=float(F.readline().strip())  #pressure 0.1- 1bar
aspen = win32.Dispatch('Apwn.Document')
aspen.InitFromArchive2(os.path.abspath('cuminNew.bkp'))
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_TEMPVAL\O-2\#1").Value= l1  
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_VALUE\O-2\#0").Value=l2   
aspen.Tree.FindNode("\Data\Blocks\B1\Input\JH_DUTY").Value=l3
aspen.Tree.FindNode("\Data\Blocks\B1\Subobjects\Operating Steps\O-2\Input\OPS_DURATION\O-2").Value=l4
aspen.Tree.FindNode("\Data\Blocks\B1\Input\COND_PRES").Value=l5
aspen.Engine.Run2()
C1=aspen.Tree.FindNode("\Data\Streams\S3\Output\MASSFRAC\MIXED\GAMMA-01").Value  #mass gamma >0.14
C2=aspen.Tree.FindNode("\Data\Streams\S3\Output\MASSFRAC\MIXED\ANETH-01").Value  #mass anethe >0.42
C3= aspen.Tree.FindNode("\Data\Streams\S3\Output\TEMP_OUT\MIXED").Value   #T <150
c1=0.136-C1
c2=0.416-C2
c3=C3-150
Obj=(l3*0.1192*(l4+0.5))*10
with open("output.txt", "w") as file:
  # lines = [f"{Obj:1.8f}\n", f"{c1:1.8f}\n", f"{c2:1.8f}"]#,f"{c3:1.8f}" ]
  # lines = [f"{Obj:1.8f}\n"]#, f"{c3:1.8f}" ]
  # file.writelines(lines)
  file.write(f"{Obj} {c1} {c2} {c3}")
with open("ObJ.txt", "w") as O:
   O.write(f"{Obj} ")

#print(Obj)
#file = open("output.txt")
#print(file.read())
sys.exit(0)